package com.sys.log.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.app.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.aspect.Log;
import com.sys.log.entity.SysLog;
import com.sys.log.service.SysLogService;


@Controller
@RequestMapping("/sysLog")
public class SysLogController {

	 @Autowired
	 SysLogService sysLogService;
	
	  @Log("查询后台日志列表")
	  @RequiresPermissions("SysLogList")
	  @RequestMapping(value="/list.do", method={RequestMethod.POST})
	  @ResponseBody
	  public Map<String, Object> list(ServletRequest request,ServletResponse response,Page<SysLog> page,SysLog view)
	  {
	    Map<String, Object> map = new HashMap<String, Object>();
	    List<SysLog> list = this.sysLogService.getSysLogViews(page, view);
	    map.put("records", list);
	    map.put("total", page.getTotal());
	    return map;
	  }
	  
	  @Log("进入后台日志管理")
	  @RequiresPermissions("SysLog")
	  @RequestMapping("/golist.do")
	  public String tolist()
	  {
	    return "module/syslog/list";
	  }
	  
	  @Log("查询后台日志")
	  @RequiresPermissions("EditSysLog")
	  @RequestMapping("/goEdit.do")
	  public ModelAndView goEdit(SysLog entity)
	  {
	    Map<String, Object> map = new HashMap<String, Object>();
	    if (entity.getId() != null) {
	      entity = (SysLog)this.sysLogService.selectById(entity.getId());
	    }
	    map.put("entity", entity);
	    return new ModelAndView("module/syslog/edit", map);
	  }
	  
	  @Log("保存后台日志")
	  @RequiresPermissions("EditSysLog")
	  @RequestMapping(value="/save.do", method=RequestMethod.POST)
	  @ResponseBody
	  public Result save(SysLog entity)
	  {
	    boolean n = this.sysLogService.insertOrUpdate(entity);
	    return Result.returnResult(n);
	  }
	  
	  @Log("删除后台日志")
	  @RequiresPermissions("DelSysLog")
	  @RequestMapping(value="/del.do", method=RequestMethod.POST)
	  @ResponseBody
	  public Result del(SysLog entity)
	  {
	    boolean n = this.sysLogService.deleteById(entity.getId());
	    return Result.returnResult(n);
	  }
	  
	  @Log("修改后台日志")
	  @RequiresPermissions("UpdateSysLog")
	  @RequestMapping(value="/update.do", method=RequestMethod.POST)
	  @ResponseBody
	  public Result update(SysLog entity)
	  {
	    boolean n = this.sysLogService.updateById(entity);
	    return Result.returnResult(n);
	  }
}
